package com.generic;

import java.util.Date;

/**实例化泛型
 * @author dell
 *
 */
public class InstanceOfClass {

    public static void main(String[] args) {

        Date date=createInstance(Date.class);
        String s=createInstance(String.class);
        System.out.println("date="+date+", string="+s);
    }

     public static <T> T createInstance(Class<T> cls) {
         T obj=null;
         try {
             obj=cls.newInstance();
         } catch (Exception e) {
             obj=null;
         }
         return obj;
     }

}